<template>
	<el-main>
		<el-card shadow="never">
			<el-tabs tab-position="top">

				<el-tab-pane label="系统设置">
					<el-form ref="form" :model="sys" label-width="180px" style="margin-top: 20px;width: 700px;">
						<el-form-item label="店铺名称">
							<el-input v-model="sys.name"></el-input>
						</el-form-item>
						<el-form-item label="店铺位置">
							<el-input v-model="sys.address"></el-input>
						</el-form-item>
						<el-form-item label="位置经纬度">
							<el-input v-model="sys.lon" placeholder="经度" style="width: 150px;"></el-input>
							<el-input v-model="sys.lat" placeholder="纬度" style="width: 150px;margin-left: 15px;"></el-input>
						</el-form-item>
						<el-form-item label="logo">
							<!-- <el-input v-model="sys.logoUrl"></el-input> -->
							<sc-upload v-model="sys.logoUrl" title="上传图片"></sc-upload>
							<div class="el-form-item-msg" data-v-b33b3cf8="">建议尺寸200*200</div>
						</el-form-item>
						<el-form-item label="客服电话">
							<el-input v-model="sys.kefu"></el-input>
						</el-form-item>

						<el-form-item>
							<el-button type="primary" @click="saveForm('sys')">保存</el-button>
						</el-form-item>
					</el-form>
				</el-tab-pane>
				<el-tab-pane label="微信相关">
					<el-form ref="form" :model="wx" label-width="180px" style="margin-top: 20px;width: 700px;">
						<el-form-item label="小程序appid">
							<el-input v-model="wx.xcx_appid"></el-input>
						</el-form-item>
						<el-form-item label="小程序app sercert">
							<el-input v-model="wx.xcx_appservert"></el-input>
						</el-form-item>
						<el-form-item label="公众号appid">
							<el-input v-model="wx.gzh_appid"></el-input>
							<!-- <div class="el-form-item-msg" data-v-b33b3cf8="">关闭后普通用户无法登录，仅允许管理员角色登录</div> -->
						</el-form-item>
						<el-form-item label="公众号app sercert">
							<el-input v-model="wx.gzh_appsercert"></el-input>
						</el-form-item>
						<el-form-item label="微信商户号">
							<el-input v-model="wx.merchant_id"></el-input>
						</el-form-item>
						<el-form-item label="微信商户api v2秘钥">
							<el-input v-model="wx.api_v2" placeholder="32位字符"></el-input>
						</el-form-item>
						<el-form-item label="微信商户api v3秘钥">
							<el-input v-model="wx.api_v3" placeholder="32位字符"></el-input>
						</el-form-item>
						<el-form-item>
							<el-button type="primary" @click="saveForm('wx')">保存</el-button>
						</el-form-item>
					</el-form>
				</el-tab-pane>
				<el-tab-pane label="简介配置">
					<el-form ref="form" :model="about" label-width="180px" style="margin-top: 20px;width: 700px;">
						   <el-tabs tab-position="left">
						     <el-tab-pane :label="item.name" v-for="(item,index) in about" :key="index">
								 <sc-editor v-model="item.settings" placeholder="请输入" :templates="templates" :height="400"></sc-editor>
								<el-button type="default" style="margin-top: 20px;" @click="delabout(item.id)">删除</el-button>

								 <el-button type="primary" style="margin-top: 20px;" @click="saveForm('about_content')">保存</el-button>
							 </el-tab-pane>

							 <el-tab-pane label="+新增简介栏目">
									<el-form ref="form" :model="about_cat" label-width="110px" style="margin-top: 20px;width: 400px;">
										<el-form-item label="名称">
											<el-input v-model="about_cat.name" placeholder="必填"></el-input>
										</el-form-item>
										<el-form-item label="别名">
											<el-input v-model="about_cat.alias_name" placeholder="必填 , 建议为英文字母"></el-input>
										</el-form-item>
										<el-form-item>
											<el-button type="primary" @click="saveForm('about')">保存</el-button>
										</el-form-item>
									</el-form>
							 </el-tab-pane>

						   </el-tabs>
					</el-form>
				</el-tab-pane>
				<el-tab-pane label="订单配置">
					<el-form ref="form" :model="order" label-width="180px" style="margin-top: 20px;width: 700px;">
						<el-form-item label="支持自提">
							<el-switch v-model="order.ziti" active-value="1" inactive-value="0"></el-switch>
						</el-form-item>
						<el-form-item label="支持评价订单">
							<el-switch v-model="order.allow_evaluate" active-value="1" inactive-value="0"></el-switch>
						</el-form-item>
						<el-form-item label="详细页显示商品评价">
							<el-switch v-model="order.show_evaluate" active-value="1" inactive-value="0"></el-switch>
						</el-form-item>
						<el-form-item label="自动确认收货天数">
							<el-input v-model="order.shou_day" placeholder=""></el-input>
							<div class="el-form-item-msg" data-v-b33b3cf8="">默认为7天，即用户7天后未确认收货，则系统默认确认自动收货</div>
						</el-form-item>
						<el-form-item>
							<el-button type="primary" @click="saveForm('order')">保存</el-button>
						</el-form-item>
					</el-form>
				</el-tab-pane>
				<el-tab-pane label="店铺wifi设置">
					<el-form ref="form" :model="order" label-width="180px" style="margin-top: 20px;width: 700px;">

						<el-form-item>
							<el-button type="primary" @click="saveForm('order')">保存</el-button>
						</el-form-item>
					</el-form>
				</el-tab-pane>



			</el-tabs>
		</el-card>
	</el-main>
</template>

<script>
	import { defineAsyncComponent } from 'vue';
	const scEditor = defineAsyncComponent(() => import('@/components/scEditor'));
	export default {
		components: {
			scEditor
		},
		name: 'system',
		data() {
			return {
				about_cat:{},
				about:{},
				wx:{},
				sys: {},
				order:{},
			}
		},
		mounted() {
			 this.getdata()

		},
		methods: {
			async delabout(id = 0){
				var res = await this.$API.system.universal.handle.post({'id':id},'/system/store_setting_del');
				if(res.code == 200){
					this.getdata()
				}
			},
			async saveForm(type=''){
				var data = {}
				if(type=='about'){
					  this.about_cat.act = type
					  data = this.about_cat
				}
				if(type == 'sys'){
					  this.sys.act = type
					  data = this.sys
				}
				if(type == 'wx'){
					  this.wx.act = type
					  data = this.wx
				}
				if(type == 'about_content'){
					  data.act = type
					  data.data = this.about
				}
				if(type == 'order'){
					  this.order.act = type
					  data = this.order
				}
                var res = await this.$API.system.universal.handle.post(data,'/system/store_setting');
				if(res.code == 200){
					 this.$message.success("操作成功")
					 this.about_cat = {}
					 this.getdata()
				}else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			},
			async getdata(){
				var res = await this.$API.system.universal.handle.post({},'/system/store_setting');
				if(res.code == 200){
					  this.wx = res.data.wx ?? {}
					  this.sys = res.data.system ?? {}
					  this.about = res.data.about ?? []
					  this.order = res.data.order ?? {}
				}
			},
			table_edit(row){
				if(row.isSet){
					row.isSet = false
				}else{
					row.isSet = true
				}
			},
			table_del(row, index){
				this.setting.splice(index, 1)
			},
		}
	}
</script>

<style>
</style>
